package com.aga.app.service;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import org.springframework.stereotype.Service;

import com.aga.app.domain.Rss;

@Service
public class PeerFlyFeedFetcherService  { 
	
	public List<Rss.Channel.Item> getFeedUnmarshal(String url) {
		 
		try {
			JAXBContext jc = JAXBContext.newInstance( "com.aga.app.domain" );
			Unmarshaller u = jc.createUnmarshaller();
			Rss rss=(Rss)u.unmarshal(new URL(url));
			return rss.getChannel().getItem();
		} catch (JAXBException e) { 
			e.printStackTrace();
		} catch (MalformedURLException e) { 
			e.printStackTrace();
		}
		return null;
	}
	 
}
